package com.resume.aipeople.service.ai.model;

import ai.z.openapi.core.Constants;
import ai.z.openapi.service.model.ChatCompletionCreateParams;
import ai.z.openapi.service.model.ChatMessage;
import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;
import reactor.core.publisher.Mono;

import java.util.List;

/**
 * GLM-4.5模型策略实现
 */
@Component
@Slf4j
public class GLM45ModelStrategy implements LLMModelStrategy {
    
    @Override
    public String getModelName() {
        return Constants.ModelChatGLM4_5;
    }
    
    @Override
    public String getDisplayName() {
        return "GLM-4.5";
    }
    
    @Override
    public String getDescription() {
        return "智谱AI GLM-4.5模型，最新版本，具备更强的推理和创作能力";
    }
    
    @Override
    public ChatCompletionCreateParams buildRequest(List<ChatMessage> messages, float temperature, int maxTokens) {
        // 为角色扮演优化参数，严格控制输出长度
        return ChatCompletionCreateParams.builder()
                .model(getModelName())
                .messages(messages)
                .temperature(0.8f)  // 提高创意性，适合角色扮演
                .maxTokens(200)     // 严格控制输出长度，保持对话简洁
                .topP(0.9f)         // 增加多样性
                .build();
    }
    
    @Override
    public Mono<String> processResponse(Object response) {
        return Mono.fromCallable(() -> {
            if (response != null) {
                String result = response.toString();
                log.info("GLM-4.5模型响应处理完成，内容长度: {}", result.length());
                return result;
            }
            log.warn("GLM-4.5模型返回空响应");
            return "抱歉，我现在无法回应。";
        });
    }
    
    @Override
    public boolean isAvailable() {
        return true;
    }
}
